/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proteusadm;

import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Gui
 */
public class JanelaPrincipal extends javax.swing.JFrame {

    // VARIAVEIS DA ABA PRODUTO
    private String ult_cod = "";
    private String ult_com1 = "";
    private String ult_com2 = "";
    private String ult_nome = "";
    private FrameVendaProd venda = null;
    private boolean isJVOpen = false;
    private boolean isJOOpen = false;
    private ArrayList<FrameNovoOrcamento> orcamento = new ArrayList();
    //VARIAVEIS DA ABA CLIENTE
    private String ult_cliente = "";
    //VARIAVEIS DE SEGURANÇA
    private User userLogado = null;

    public JanelaPrincipal() {
        Dimension tela = getSize();

        this.setLocation((int) tela.getHeight() + 100, (int) tela.getWidth() / 2);
        this.setTitle("Proteus ADM -- 6N Developers");
//       this.setAlwaysOnTop(true);
        initComponents();
        this.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel15 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tabelaProd = new javax.swing.JTable();
        jButton3 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel16 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tabelaClientes = new javax.swing.JTable();
        jButton5 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jPanel17 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jButtonOrcamentos = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jTextField9 = new javax.swing.JTextField();
        jScrollPane3 = new javax.swing.JScrollPane();
        tabelaOrcamentos = new javax.swing.JTable();
        jButton6 = new javax.swing.JButton();

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTabbedPane1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N

        jPanel15.setBackground(new java.awt.Color(204, 204, 255));
        jPanel15.setEnabled(false);
        jPanel15.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jPanel15KeyReleased(evt);
            }
        });

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField1KeyReleased(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Codigo :");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Nome :");

        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField3KeyReleased(evt);
            }
        });

        jTextField4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField4ActionPerformed(evt);
            }
        });
        jTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField4KeyReleased(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel3.setText("Preço entre :");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel4.setText("De R$ ");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel5.setText("até R$ ");

        jTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField5KeyReleased(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton1.setText("Pesquisar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton1KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jButton1KeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGap(42, 42, 42)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(130, 130, 130)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3))
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel5)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(20, 20, 20))
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4))
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel15Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        tabelaProd.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Descrição", "Preço", "Quantidade"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaProd.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        tabelaProd.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        tabelaProd.setUpdateSelectionOnSort(false);
        tabelaProd.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaProdMouseClicked(evt);
            }
        });
        tabelaProd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tabelaProdKeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(tabelaProd);
        tabelaProd.getColumnModel().getColumn(0).setPreferredWidth(10);
        tabelaProd.getColumnModel().getColumn(1).setPreferredWidth(200);
        tabelaProd.getColumnModel().getColumn(2).setPreferredWidth(7);
        tabelaProd.getColumnModel().getColumn(3).setPreferredWidth(5);

        jButton3.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton3.setText("Cadastrar Novo Produto");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton3)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 692, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Produtos", jPanel1);

        jPanel16.setBackground(new java.awt.Color(153, 153, 255));
        jPanel16.setEnabled(false);
        jPanel16.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jPanel16KeyReleased(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Nome :");

        jTextField7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField7ActionPerformed(evt);
            }
        });
        jTextField7.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField7KeyReleased(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton2.setText("Pesquisar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jButton2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButton2KeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jButton2KeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel16Layout = new javax.swing.GroupLayout(jPanel16);
        jPanel16.setLayout(jPanel16Layout);
        jPanel16Layout.setHorizontalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel16Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel7)
                .addGap(29, 29, 29)
                .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 468, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23))
        );
        jPanel16Layout.setVerticalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17))
        );

        tabelaClientes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Nome"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaClientesMouseClicked(evt);
            }
        });
        tabelaClientes.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tabelaClientesKeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(tabelaClientes);
        tabelaClientes.getColumnModel().getColumn(0).setPreferredWidth(60);
        tabelaClientes.getColumnModel().getColumn(1).setPreferredWidth(380);

        jButton5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton5.setText("Cadastrar Novo Cliente");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel16, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel16, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 495, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton5)
                .addGap(0, 11, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Clientes", jPanel2);

        jPanel17.setBackground(new java.awt.Color(153, 153, 153));
        jPanel17.setEnabled(false);
        jPanel17.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jPanel17KeyReleased(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel8.setText("Nome :");

        jTextField8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField8ActionPerformed(evt);
            }
        });
        jTextField8.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField8KeyReleased(evt);
            }
        });

        jButtonOrcamentos.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButtonOrcamentos.setText("Pesquisar");
        jButtonOrcamentos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOrcamentosActionPerformed(evt);
            }
        });
        jButtonOrcamentos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jButtonOrcamentosKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jButtonOrcamentosKeyReleased(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("Cliente : ");

        jTextField9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField9ActionPerformed(evt);
            }
        });
        jTextField9.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField9KeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel17Layout = new javax.swing.GroupLayout(jPanel17);
        jPanel17.setLayout(jPanel17Layout);
        jPanel17Layout.setHorizontalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel17Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jLabel9)
                .addGap(2, 2, 2)
                .addComponent(jTextField8, javax.swing.GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jButtonOrcamentos, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel17Layout.setVerticalGroup(
            jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel17Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel17Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonOrcamentos, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jTextField9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17))
        );

        tabelaOrcamentos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Nome", "Cliente"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabelaOrcamentos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaOrcamentosMouseClicked(evt);
            }
        });
        tabelaOrcamentos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                tabelaOrcamentosKeyReleased(evt);
            }
        });
        jScrollPane3.setViewportView(tabelaOrcamentos);
        tabelaOrcamentos.getColumnModel().getColumn(0).setPreferredWidth(60);
        tabelaOrcamentos.getColumnModel().getColumn(1).setPreferredWidth(380);
        tabelaOrcamentos.getColumnModel().getColumn(2).setPreferredWidth(300);

        jButton6.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jButton6.setText("Criar Novo Orçamento");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 697, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jPanel17, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 512, Short.MAX_VALUE)
                .addComponent(jButton6)
                .addContainerGap())
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(49, 49, 49)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 493, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(51, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Orçamentos", jPanel3);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 722, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        ult_cod = jTextField1.getText();
        ult_nome = jTextField4.getText();
        ult_com1 = jTextField3.getText();
        ult_com2 = jTextField5.getText();

        fazBusca(ult_cod, ult_nome, ult_com1, ult_com2);

    }//GEN-LAST:event_jButton1ActionPerformed

    private void fazBusca(String codigo, String nome, String comp1, String comp2) {

        DefaultTableModel jtable1 = (DefaultTableModel) tabelaProd.getModel();
        jtable1.setNumRows(0);
        if (!(codigo.trim()).equals("")) {

            try {
                int x = Integer.parseInt(codigo.trim());
                jTextField1.setText("");
                Produto p = Banco.buscaCodigo(x);
                if (p.getCodigo() != 0) {
                    String[] dados = {"" + p.getCodigo(), p.getDescricao(), "R$ " + p.getPreco_v(), "" + p.getQtd()};
                    jtable1.addRow(dados);
                } else {
                    JOptionPane.showMessageDialog(this, "O produto não esta cadastrado.\nPor favor verifique o codigo e volte a pesquisar.");
                }
                x = 0;
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(this, "O campo codigo deve conter APENAS numeros !!!");
                e.printStackTrace();
            }
        } // fim do if do buscacodigo
        else if (!(nome.trim()).equals("")) {
            jTextField4.setText("");
            if (!(comp1.trim()).equals("") && !(comp2.trim()).equals("")) {
                try {
                    double a = Double.parseDouble(comp1.trim().replaceAll(",", "."));
                    double b = Double.parseDouble(comp2.trim().replaceAll(",", "."));
                    ArrayList list = Banco.buscaNomePrecoEntre(nome.trim(), a, b);
                    if (list.size() != 0) {
                        for (int i = 0; i < list.size(); i++) {
                            Produto p = (Produto) list.get(i);
                            String[] dados = {"" + p.getCodigo(), p.getDescricao(), "R$ " + p.getPreco_v(), "" + p.getQtd()};
                            jtable1.addRow(dados);
                        }

                    } else {
                        JOptionPane.showMessageDialog(this, "Não foram encontrados produtos cadastrados\n que atendam as condições de sua pesquisa.");
                    }
                    jTextField3.setText("");
                    jTextField5.setText("");
                } catch (NumberFormatException e) {
                    JOptionPane.showMessageDialog(this, "Valores de preços invalidos.\nPor favor verifique os valores e volte a pesquisar.");
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {

                try {
                    ArrayList list = Banco.buscaNome(nome);
                    if (list.size() != 0) {
                        for (int i = 0; i < list.size(); i++) {
                            Produto p = (Produto) list.get(i);
                            String[] dados = {"" + p.getCodigo(), p.getDescricao(), "" + p.getPreco_v(), "" + p.getQtd()};
                            jtable1.addRow(dados);
                        }
                    } else {
                        JOptionPane.showMessageDialog(this, "Não foram encontrados produtos cadastrados para este tipo de produto.");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        } else {
            JOptionPane.showMessageDialog(this, "Pelo menos, um dos campos CODIGO ou NOME deve ser preenchido.");
        }
    }

    private void jButton1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jButton1ActionPerformed(null);
        }
    }//GEN-LAST:event_jButton1KeyPressed

    private void jTextField4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField4ActionPerformed

    private void tabelaProdKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabelaProdKeyReleased

        if (evt.getKeyCode() == KeyEvent.VK_SPACE) {
            OpcoesTabelaProd();

        } else if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
            DefaultTableModel jtable1 = (DefaultTableModel) tabelaProd.getModel();
            jtable1.setNumRows(0);
            ult_cod = ult_nome = ult_com1 = ult_com2 = "";
        } else if (evt.getKeyCode() == KeyEvent.VK_F5) {
            fazBusca(ult_cod, ult_nome, ult_com1, ult_com2);
        }

        // TODO add your handling code here:
    }//GEN-LAST:event_tabelaProdKeyReleased

    private void OpcoesTabelaProd() {

        int codigo = 0;
        try {
            codigo = Integer.parseInt((String) tabelaProd.getValueAt(tabelaProd.getSelectedRow(), 0));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "Desculpe, ocorreu um erro e a pesquisa precisa ser fechada.");
            DefaultTableModel jtable1 = (DefaultTableModel) tabelaProd.getModel();
            jtable1.setNumRows(0);
        }
        ArrayList a = new ArrayList();
        a.add("Realizar venda");
        a.add("Editar Produto");
        if (orcamento.size() > 0) {
            for (int i = 0; i < orcamento.size(); i++) {
                a.add("Adionar ao orçamento " + (i + 1) + " --> " + orcamento.get(i).getTitle());
            }
        }
        a.add("Adicionar a novo Orçamento");
        Object[] opcoes = a.toArray();
        String retorno = (String) JOptionPane.showInputDialog(this, "Escolha uma ação para este produto :", "Escolha uma opção a fazer :", 3, null, opcoes, opcoes[0]);
        if (retorno.equalsIgnoreCase("Realizar venda")) {
            if (!isJVOpen) {
                try {

                    ArrayList qtd = new ArrayList();
                    Produto p = Banco.buscaCodigo(codigo);
                    for (int i = 1; i <= p.getQtd(); i++) {
                        qtd.add(i);
                    }

                    Object[] qtd2 = qtd.toArray();
                    String q = "" + JOptionPane.showInputDialog(this, "Escolha uma quantidade :", "Escolha uma quantidade :", JOptionPane.QUESTION_MESSAGE, null, qtd2, qtd2[0]);
                    if (!q.equalsIgnoreCase(""+null)) {
                        venda = new FrameVendaProd(this);
                        isJVOpen = true;

                        venda.addProdutos(p, Integer.parseInt(q));
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this, "O não o sistema está morto e precisa ser fechado!");
                }

            } else {
                try {

                    ArrayList qtd = new ArrayList();
                    Produto p = Banco.buscaCodigo(codigo);
                    for (int i = 1; i <= p.getQtd(); i++) {
                        qtd.add(i);
                    }
                    Object[] qtd2 = qtd.toArray();
                    String q = "" + JOptionPane.showInputDialog(this, "Escolha uma quantidade :", "Escolha uma quantidade :", JOptionPane.QUESTION_MESSAGE, null, qtd2, qtd2[0]);
                    if (!q.equalsIgnoreCase(""+null)) {
                        venda.addProdutos(p, Integer.parseInt(q));
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this, "Oh não !!! O sistema está morto e precisa ser fechado!!!");

                }

//                    venda.addProdutos(Banco.buscaCodigo(codigo));
            }
        } else if (retorno.equalsIgnoreCase("Editar Produto")) {

            DialogAutenticar autenticar = new DialogAutenticar(this, true);
            if (userLogado != null && userLogado.getEditar_p() == true) {
//                    JOptionPane.showMessageDialog(this, "Logado como "+userLogado.getUser());
                FrameEditarProd frame = new FrameEditarProd(this, "Proteus ADM --- Logado como " + userLogado.getUser());
                Produto p = Banco.buscaCodigo(codigo);
                frame.getJTextField1().setText("" + p.getCodigo());
                frame.getJTextField2().setText(p.getNome());
                frame.getJTextArea1().setText(p.getDescricao());
                frame.getJTextField3().setText("" + p.getPreco_c());
                frame.getJTextField4().setText("" + p.getPreco_v());
                frame.getJTextField5().setText("" + p.getQtd());
                userLogado = null;
            } else {
                JOptionPane.showMessageDialog(this, "<html><h3><b>Não foi possivel autenticar seu usuario.</b></h3></html>\nVerifique usuario e senha digitados ou seu usuario\n não possui permissões para acessar este conteudo.");
                userLogado = null;
            }


        } else if (retorno.equalsIgnoreCase("Adicionar a novo Orçamento")) {


            ProdutoOrcamento p = Banco.buscaCodigoOrcamento(codigo);
            ArrayList qtd = new ArrayList();
            for (int i = 1; i <= p.getQtd(); i++) {
                qtd.add(i);
            }

            Object[] qtd2 = qtd.toArray();
            String q = "" + JOptionPane.showInputDialog(this, "Escolha uma quantidade :", "Escolha uma quantidade :", JOptionPane.QUESTION_MESSAGE, null, qtd2, qtd2[0]);
            
            if (!q.equalsIgnoreCase(""+null)) {
                FrameNovoOrcamento frame = new FrameNovoOrcamento(this);
                frame.addProdutos(p, Integer.parseInt(q));
                orcamento.add(frame);
            }
        } else {
            for (int i = 2; i < opcoes.length - 1; i++) {
                if (retorno.equalsIgnoreCase("" + opcoes[i])) {
                    ProdutoOrcamento p = Banco.buscaCodigoOrcamento(codigo);
                    ArrayList qtd = new ArrayList();
                    for (int x = 1; x <= p.getQtd(); x++) {
                        qtd.add(x);
                    }
                    Object[] qtd2 = qtd.toArray();
                    String q = "" + JOptionPane.showInputDialog(this, "Escolha uma quantidade :", "Escolha uma quantidade :", JOptionPane.QUESTION_MESSAGE, null, qtd2, qtd2[0]);
                    if (!q.equalsIgnoreCase(""+null)) {
                        orcamento.get(i - 2).addProdutos(p, Integer.parseInt(q));
                        break;
                    }
                }
            }
        }
    }

    private void jButton1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton1KeyReleased
    }//GEN-LAST:event_jButton1KeyReleased

    private void jTextField4KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField4KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jButton1ActionPerformed(null);
        }
    }//GEN-LAST:event_jTextField4KeyReleased

    private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jButton1ActionPerformed(null);
        }        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1KeyReleased

    private void jTextField3KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jButton1ActionPerformed(null);
        }        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField3KeyReleased

    private void jTextField5KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField5KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jButton1ActionPerformed(null);
        }
        if (evt.getKeyCode() == KeyEvent.VK_HOME) {
            Testes teste = new Testes();
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5KeyReleased

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        FrameCadastraProd frame = new FrameCadastraProd(this);
        frame.getJTextField1().setText("" + (Banco.ultimo_codigo() + 1));
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jPanel15KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel15KeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel15KeyReleased

    private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField7ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField7ActionPerformed

    private void jTextField7KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField7KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            jButton2ActionPerformed(null);
        }
    }//GEN-LAST:event_jTextField7KeyReleased

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        ult_cliente = jTextField7.getText().trim();
        fazBuscaCliente(jTextField7.getText().trim());

    }//GEN-LAST:event_jButton2ActionPerformed

    /**
     * ********************************************************************************************************
     *
     * METODOS DA ABA CLIENTES
     *
     **********************************************************************************************************
     */
    private void fazBuscaCliente(String nome) {
        DefaultTableModel jtable1 = (DefaultTableModel) tabelaClientes.getModel();
        jtable1.setNumRows(0);
        ult_cliente = nome;
        ArrayList list = Banco.buscaCliente(nome);
        if (list.size() != 0) {
            for (int i = 0; i < list.size(); i++) {
                Cliente p = (Cliente) list.get(i);
                String[] dados = {"" + p.getCodigo(), Tools.UpperOneofWord(p.getNome() + " " + p.getSobrenome())};
                jtable1.addRow(dados);
            }


        } else {
            JOptionPane.showMessageDialog(this, "Não foram encontrados clientes cadastrados\n com este nome.");
        }
    }

    private void jButton2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton2KeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2KeyPressed

    private void jButton2KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButton2KeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2KeyReleased

    private void jPanel16KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel16KeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel16KeyReleased

    private void tabelaClientesKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabelaClientesKeyReleased
        // TABELA ABA CLIENTES
        if (evt.getKeyCode() == KeyEvent.VK_SPACE) {

            OpcoesTabelaCliente();
        }
    }//GEN-LAST:event_tabelaClientesKeyReleased
    public void atualizaTabelaClientes() {
        fazBuscaCliente(ult_cliente);
    }

    public void OpcoesTabelaCliente() {
        int codigo = 0;
        try {
            codigo = Integer.parseInt((String) tabelaClientes.getValueAt(tabelaClientes.getSelectedRow(), 0));
        } catch (NumberFormatException e) {
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, "Desculpe ocorreu um erro e a pesquisa precisa ser fechada.");
            DefaultTableModel jtable1 = (DefaultTableModel) tabelaClientes.getModel();
            jtable1.setNumRows(0);
        }
        Object[] opcoes = {"Ver Informações do Cliente", "Editar Cliente", "Cadastrar Novo Cliente"};
        String retorno = (String) JOptionPane.showInputDialog(this, "Escolha uma opção a fazer :", "Escolha uma ação :", 3, null, opcoes, opcoes[0]);
        if (retorno.equals("Ver Informações do Cliente")) {
            Cliente p = Banco.buscaClienteCod(codigo);
            FrameVerCliente frame = new FrameVerCliente(this.getTitle());
            frame.getJTextField1().setText("" + p.getCodigo());
            frame.getJTextField2().setText(Tools.UpperOneofWord(p.getNome()).trim());
            frame.getJTextField3().setText(Tools.UpperOneofWord(p.getSobrenome()).trim());
            frame.getJTextArea2().setText("" + p.getEndereco());
            frame.getJTextField4().setText("" + p.getTelefone());
            frame.getJTextField5().setText("" + p.getCPF());
            frame.getJTextField6().setText("" + p.getCelular());

        } else if (retorno.equals("Editar Cliente")) {
            DialogAutenticar autenticar = new DialogAutenticar(this, true);
            if (userLogado != null && userLogado.getEditar_c() == true) {
                FrameEditarCliente frame = new FrameEditarCliente(this, "Proteus ADM --- Logado como " + userLogado.getUser());
                Cliente p = Banco.buscaClienteCod(codigo);
                frame.getJTextField1().setText("" + p.getCodigo());
                frame.getJTextField2().setText(Tools.UpperOneofWord(p.getNome()).trim());
                frame.getJTextField3().setText(Tools.UpperOneofWord(p.getSobrenome()).trim());
                frame.getJTextArea2().setText("" + p.getEndereco());
                frame.getJTextField4().setText("" + p.getTelefone());
                frame.getJTextField5().setText("" + p.getCPF());
                frame.getJTextField6().setText("" + p.getCelular());
                userLogado = null;
            } else {
                JOptionPane.showMessageDialog(this, "<html><h3><b>Não foi possivel autenticar seu usuario.</b></h3></html>\nVerifique usuario e senha digitados ou seu usuario\n não possui permissões para acessar este conteudo.");
                userLogado = null;
            }

        } else if (retorno.equals("Cadastrar Novo Cliente")) {
            jButton5ActionPerformed(null); // chama FrameCadastraCliente
        }
    }

    /*
     **********************************************************************************************************
     *
     * METODOS DA ABA ORÇAMENTOS
     *
     **********************************************************************************************************
     */
    public void buscaOrcamento(String nome, String cliente) {
        DefaultTableModel jtable1 = (DefaultTableModel) tabelaOrcamentos.getModel();
        jtable1.setNumRows(0);

        if (!(nome.trim()).equals("")) {
            jTextField9.setText("");
            ArrayList list = Banco.buscaOrcamento(nome.trim());
            if (list.size() != 0) {
                for (int i = 0; i < list.size(); i++) {
                    Orcamento p = (Orcamento) list.get(i);
                    String[] dados = {"" + p.getID(), p.getNome(), p.getCliente().getNome() + "" + p.getCliente().getSobrenome()};
                    jtable1.addRow(dados);
                }

            } else {
                JOptionPane.showMessageDialog(this, "Não foram encontrados orçamentos cadastrados\n que atendam as condições de sua pesquisa.");
            }

        } else if (!(cliente.trim()).equals("")) {

            jTextField8.setText("");
            ArrayList list = Banco.buscaOrcamentoCliente(cliente.trim());
            if (list.size() != 0) {
                for (int i = 0; i < list.size(); i++) {
                    Orcamento p = (Orcamento) list.get(i);
                    String[] dados = {"" + p.getID(), p.getNome(), p.getCliente().getNome() + "" + p.getCliente().getSobrenome()};
                    jtable1.addRow(dados);
                }

            } else {
                JOptionPane.showMessageDialog(this, "Não foram encontrados orçamentos cadastrados para este cliente.");
            }

        } else {
            JOptionPane.showMessageDialog(this, "Pelo menos, um dos campos NOME ou CLIENTE deve ser preenchido.");
        }
    }
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

        FrameCadastraCliente cliente = new FrameCadastraCliente(this);

    }//GEN-LAST:event_jButton5ActionPerformed

    private void tabelaProdMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaProdMouseClicked
        if (evt.getButton() == MouseEvent.BUTTON3) {
            OpcoesTabelaProd();
        }
    }//GEN-LAST:event_tabelaProdMouseClicked

    private void tabelaClientesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaClientesMouseClicked
        if (evt.getButton() == MouseEvent.BUTTON3) {
            OpcoesTabelaCliente();
        }
    }//GEN-LAST:event_tabelaClientesMouseClicked

    private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField8ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField8ActionPerformed

    private void jTextField8KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField8KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            buscaOrcamento(jTextField9.getText(), jTextField8.getText());
        }
    }//GEN-LAST:event_jTextField8KeyReleased

    private void jButtonOrcamentosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOrcamentosActionPerformed
        buscaOrcamento(jTextField9.getText(), jTextField8.getText());
    }//GEN-LAST:event_jButtonOrcamentosActionPerformed

    private void jButtonOrcamentosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonOrcamentosKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonOrcamentosKeyPressed

    private void jButtonOrcamentosKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jButtonOrcamentosKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonOrcamentosKeyReleased

    private void jPanel17KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel17KeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel17KeyReleased

    private void jTextField9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField9ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField9ActionPerformed

    private void jTextField9KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField9KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            buscaOrcamento(jTextField9.getText(), jTextField8.getText());
        }
    }//GEN-LAST:event_jTextField9KeyReleased

    private void tabelaOrcamentosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaOrcamentosMouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_tabelaOrcamentosMouseClicked

    private void tabelaOrcamentosKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tabelaOrcamentosKeyReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_tabelaOrcamentosKeyReleased

    public ArrayList getOrcamento() {
        return orcamento;

    }

    public void atualizaTabela() {
        fazBusca(ult_cod, ult_nome, ult_com1, ult_com2);

    }

    public void atualizaFrameVendas() {
        venda = null;
        isJVOpen = false;
    }

    public void setUserLogado(User user) {
        this.userLogado = user;
    }
    /**
     * @param args the command line arguments
     */
//    public static void main(String args[]) {
//        /*
//         * Set the Nimbus look and feel
//         *
//         * //<editor-fold defaultstate="collapsed" desc=" Look and feel setting
//         * code (optional) "> /* If Nimbus (introduced in Java SE 6) is not
//         * available, stay with the default look and feel. For details see
//         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
//         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info :
//                    javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
//                    null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
//                    null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
//                    null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(JanelaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
//                    null, ex);
//        } //</editor-fold>

    /*
     * Create and display the form
     */
//        
//        
//        java.awt.EventQueue.invokeLater(new Runnable() {
//
//            public void run() {
//                new JanelaPrincipal().setVisible(true);
//            }
//        });
//    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButtonOrcamentos;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    private javax.swing.JTextField jTextField9;
    private javax.swing.JTable tabelaClientes;
    private javax.swing.JTable tabelaOrcamentos;
    private javax.swing.JTable tabelaProd;
    // End of variables declaration//GEN-END:variables
}
